package kim.artemis.rpc.demo.client.controller;

import kim.artemis.rpc.core.annotation.ArtemisRpcReference;
import kim.artemis.rpc.demo.modal.Demo;
import kim.artemis.rpc.demo.service.DemoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Slf4j
@RestController
public class DemoController {

    @ArtemisRpcReference
    DemoService demoService;

    @GetMapping("/demo")
    public String demo (String id) {
        long startTime = System.currentTimeMillis();
        Demo demo = demoService.loadDemo(id);
        long endTime = System.currentTimeMillis();
        long timeLong = endTime - startTime;
        double timeDouble= Double.parseDouble(Long.toString(timeLong));
        log.info("该方法执行时间为" + timeDouble+ "毫秒，即" + timeDouble/(double)1000 + "秒");
        log.info("demo: " +demo.toString());
        return demo.toString();
    }

    /**
     * 无返回演示
     * @param id
     */
    @GetMapping("/noresult/{id}")
    public void noresultDemo (@PathVariable  String id) {
        Demo demo = new Demo();
        demo.setDemoGroup("testDemoGroup");
        demo.setDemoName("teseDemoName");
        demo.setDemoSort(1000);
        demo.setDemoTime(new Date());
        long startTime = System.currentTimeMillis();
        demoService.noResult(demo);
        long endTime = System.currentTimeMillis();
        long timeLong = endTime - startTime;
        double timeDouble= Double.parseDouble(Long.toString(timeLong));
        log.info("该方法执行时间为" + timeDouble+ "毫秒，即" + timeDouble/(double)1000 + "秒");
    }

}
